
//消息类型：0文本、1图片、2视频、3语音、4文件
enum Msg_Type {
    TEXT,
    PICTURE,
    VIDEO,
    VOICE,
    FILE,
}

enum E_event {
    TYPING = 1, //输入中
    READ = 2, //消息已读
    RECALL = 3, //消息撤回
}
enum E_Action {
    ACK =  10, //服务端已收到消息
    THE_OTHER_TYPING, //对方正在输入中
    THE_OTHER_READ, //消息被对方已读
    THE_RECALLED,  //消息已撤回
    RECALL_ALLOW,  //允许消息撤回
    RECALL_FORBID, //禁止消息撤回
}

class MsgEvent {
    isGroup?: boolean; //是不是group消息
    event? :  E_event; //（客户端携带）事件。
    action?: E_Action; //事件动作,（服务端赋值或客户端携带）动作。事件产生动作
    chatId?: string; //聊天关系ID
    sendTo?: string; //事件消息投递给谁。如果不是群聊，则客户端携带，是群聊则不用携带
    localId?: bigint; //本地ID
    msgId?:   bigint;   //（客户端携带）唯一ID

    constructor() {

    }

    static CreateEventTyping(chatId: string,sendTo: string):MsgEvent{
        let msgEvent = new MsgEvent();
        msgEvent.event = E_event.TYPING;
        msgEvent.chatId = chatId;
        msgEvent.sendTo = sendTo;
        return msgEvent;
    }

    //如果传参isGroup是true，则不需要sendTo
    static CreateEventRead(msgId: bigint, chatId:string, isGroup: boolean,sendTo:string  = ""){
        let msgEvent = new MsgEvent();
        msgEvent.event = E_event.READ;
        msgEvent.isGroup = isGroup;
        msgEvent.chatId = chatId;
        msgEvent.msgId = msgId;
        if (!isGroup){
            msgEvent.sendTo = sendTo;
        }
        return msgEvent
    }

    //如果传参isGroup是true，则不需要sendTo
    CreateEventRecall(msgId: bigint, chatId:string, isGroup: boolean,sendTo:string  = ""){
        let msgEvent = new MsgEvent();
        msgEvent.event = E_event.RECALL;
        msgEvent.isGroup = isGroup;
        msgEvent.chatId = chatId;

        msgEvent.msgId = msgId;
        if (!isGroup){
            msgEvent.sendTo = sendTo;
        }
        return msgEvent
    }
}


class ChatMessage {
    isGroup: boolean; //是不是group消息
    receiver: string; //消息的接收者
    sender: string; //消息的发送者
    content: string; //消息文本内容
    type: number;  //消息类型：0文本、1图片、2视频、3语音、4文件
    urlRef: boolean; //消息内容是不是url链接
    localId: bigint; //本地ID

    chatId?:     string;     //（服务端赋值）聊天关系ID
    convId?:     bigint;     //（服务端赋值）会话ID
    id?:         bigint;     //（服务端赋值）唯一ID
    createTime?: Date ;      //（服务端赋值）消息创建时间

    unread?: boolean; //（客户端展示）未读标记
    isSelf?: boolean; //（客户端展示）自己的消息

    constructor( content: string, type: number, urlRef: boolean, receiver: string, sender: string, isGroup: boolean) {
        this.receiver = receiver;
        this.sender = sender;
        this.content = content;
        this.type = type;
        this.urlRef = urlRef;
        this.isGroup = isGroup;
        this.localId = BigInt(Date.now()); //当前时间毫秒值
    }

}

export {
    ChatMessage,
    MsgEvent,
    E_Action,
    E_event,
    Msg_Type,

}